package com.study.day1;

import com.study.common.ListNode;
import com.study.common.PrintUtil;

/**
 * 剑指 Offer 09. 用两个栈实现队列
 */
class Solution24 {

    public ListNode reverseList(ListNode head) {
        ListNode cur = head, pre = null;
        while (cur != null) {
            ListNode temp = cur.next;
            cur.next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }

    public static void main(String[] args) {
        // ======= Test Case =======
        ListNode head = ListNode.arrToLinkedList(new int[] { 1, 2, 3, 4, 5 });
        PrintUtil.printLinkedList(head);
        // ====== Driver Code ======
        Solution24 slt = new Solution24();
        ListNode res = slt.reverseList(head);
        PrintUtil.printLinkedList(res);

    }
}

